Attribute Grammars
•	Basics
•	Synthesized attributes
•	Inherited attributes
Basics
•	Represents semantic information
–	What does each nonterminal or terminal mean?
–	Ex: what value does a nonterminal or terminal have?
–	Ex: what is the corresponding parse tree? Allows assembly of parse tree during parsing stage
•	Attaches a definition to each nonterminal or terminal
Synthesized attributes
•	Fig. 4.3
•	Attributes of non-leaves computed from attributes of children nodes
•	Such attributes are called synthesized attributes
–	Values are determined “bottom-up”	
Inherited attributes
•	Sometimes nodes need values from parent
–	Typically using values from other “branches” of the tree
–	Ex: assigning type to variable
Type assignment, inherited attributes
•	Ex:
•	<declaration> ::= <type> <variable-list>
float temperature, pressure;
•	Type to assign must be passed up to
<declaration>  from “float” leaf, then down to “temperature” and “pressure”
Inherited attributes
•	Such attributes are called inherited attributes
–	Values are determined “top-down”